import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_1_25_0/testWidget/custom_input_cell.dart';
import 'package:flutter_app_1_25_0/testWidget/data_item_widget.dart';
import 'package:flutter_app_1_25_0/testWidget/image/image_view.dart';
import 'package:flutter_app_1_25_0/testWidget/pb/common/model.pb.dart';
import 'package:flutter_app_1_25_0/testWidget/pb/exercise_practise/model.pb.dart';
import 'package:websafe_svg/websafe_svg.dart';

class DataItemPage extends StatefulWidget {
  DataItemPage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _DataItemPageState createState() => _DataItemPageState();
}

class _DataItemPageState extends State<DataItemPage> {
  List<DataItem> dataList = [];

  @override
  void initState() {
    super.initState();
    for (int i = 0; i < 10; i++) {
      DataItem item = DataItem();
      TextItem textItem = TextItem();
      textItem.style = TextItemStyle.text_item_style_style1;
      if (i < 2) {
        textItem.name = '$i 听下面4段对话或独白。每段对话或独白后有1道小题，从每题所给的A、B、C三个选项中选出最佳选项。听每段对话或独白前，你有5秒钟的时间阅读每小题。听完后，每小题给出5秒钟的作答时间。每段对话或独白你将听两遍。';
      } else {
        textItem.name =
            '$i I have a lovely dog named Bobby.He looks pretty with short legs,big ears and short tail.He is my good friend and he is also easy to take care of.I walk him at least twice a day,feed him and spend time with him.He also gives his love to me in return.';
      }
      item.text = textItem;
      dataList.add(item);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Container(
          color: Colors.green,
          width: flexible(context, 860.0),
          child: ListView.builder(
              itemCount: dataList.length,
              itemBuilder: (context, index) {
                return Container(
                  margin: EdgeInsets.only(top: index > 0 ? 20 : 0),
                  child: DataItemWidget(
                    dataItem: dataList[index],
                    maxLines: 3,
                  ),
                );
              }),
        ),
      ),
    );
  }
}
